home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / utility / uwserver.zip / uwserver.tar / lib / uw_optcmd.c < prev    next >
C/C++ Source or Header  |  1991-01-25  |  2KB  |  81 lines

  1. /*
  2.  *    uw library - uw_optcmd
  3.  *
  4.  * Copyright 1986 by John D. Bruner.  All rights reserved.  Permission to
  5.  * copy this program is given provided that the copy is not sold and that
  6.  * this copyright notice is included.
  7.  */
  8. #include <sys/types.h>
  9. #include <netinet/in.h>
  10.  
  11. #include "uwlib.h"
  12.  
  13. #ifndef htons
  14. /* These should have been defined in <netinet/in.h>, but weren't (in 4.2BSD) */
  15. extern unsigned short htons(), ntohs();
  16. extern unsigned long htonl(), ntohl();
  17. #endif
  18.  
  19. uw_optcmd(uwin, optnum, optcmd, optval)
  20. UWIN uwin;
  21. uwopt_t optnum;
  22. uwoptcmd_t optcmd;
  23. union uwoptval *optval;
  24. {
  25.     register int len;
  26.     struct uwipc uwip;
  27.     extern int errno;
  28.  
  29.     /*
  30.      * Send an option command string to the server (and eventually
  31.      * to the Macintosh).
  32.      */
  33.     if (uwin != (UWIN)0) {
  34.         if (uwin->uwi_ctlfd >= 0) {
  35.             if (optnum < UW_NUMOPTS) {
  36.                 len = sizeof uwip;
  37.                 uwip.uwip_len = htons(len);
  38.                 uwip.uwip_cmd = htons(UWC_OPTION);
  39.                 uwip.uwip_option.uwop_id = htonl(uwin->uwi_id);
  40.                 uwip.uwip_option.uwop_opt = htons(optnum);
  41.                 uwip.uwip_option.uwop_cmd = htons(optcmd);
  42.                 switch (optcmd) {
  43.                 case UWOC_SET:
  44.                     if (optval == (union uwoptval *)0) {
  45.                         uwin->uwi_uwerr = UWE_INVAL;
  46.                         break;
  47.                     } 
  48.                     uwip.uwip_option.uwop_val = *optval;
  49.                     uw_hton(uwin->uwi_type, optnum,
  50.                         (char *)&uwip.uwip_option.uwop_val);
  51.                     /* no break */
  52.                 case UWOC_ASK:
  53.                 case UWOC_DO:
  54.                 case UWOC_DONT:
  55.                 case UWOC_WILL:
  56.                 case UWOC_WONT:
  57.                     if (write(uwin->uwi_ctlfd, (char *)&uwip,
  58.                         len) < 0) {
  59.                         uwin->uwi_uwerr = UWE_ERRNO;
  60.                         uwin->uwi_errno = errno;
  61.                     } else
  62.                         uwin->uwi_uwerr = UWE_NONE;
  63.                     break;
  64.                 default:
  65.                     uwin->uwi_uwerr = UWE_INVAL;
  66.                     break;
  67.                 }
  68.             } else
  69.                 uwin->uwi_uwerr = UWE_INVAL;
  70.         }
  71.         uwerrno = uwin->uwi_uwerr;
  72.         if (uwin->uwi_uwerr == UWE_NONE)
  73.             return(0);
  74.         else
  75.             return(-1);
  76.     } else {
  77.         uwerrno = UWE_INVAL;
  78.         return(-1);
  79.     }
  80. }
  81.